package com.springboot.mybatis.service.rabbitmq;

import com.rabbitmq.client.*;
import com.rabbitmq.tools.json.JSONUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author sunyt31481
 * @date 2020/8/12 16:59
 * @description
 */
public class Customer1FanOutDemo {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connect = RabbitMqUtil.getConnect();
        Channel channel = connect.createChannel();
        channel.exchangeDeclare("logs", "fanout");

        //创建临时队列
        String queueName = channel.queueDeclare().getQueue();

        //将临时队列和交换机绑定
        channel.queueBind(queueName, "logs", "");

        channel.basicConsume(queueName, true, new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println(new String(body));
            }
        });
    }
}
